<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title>老师端作业章节批改页</title>
		<link rel="stylesheet" href="../../css/mui.min.css" />
		<link rel="stylesheet" href="../../css/timecontrol.min.css" />
		<link rel="stylesheet" href="../../css/CFNetPP_Base.css">
		<link rel="stylesheet" href="../../css/base.css"/>
		<link rel="stylesheet" type="text/css" href="../../css/weui.min.css">
		<link rel="stylesheet" type="text/css" href="../../css/attachmentCss.css">
		<style>
			body {
			}
			.clearfix {
				content: '';
				display: block;
				clear: both;
			}
			.title_ms {
				margin-left: 18px;
				font-size: 15px
			}
			.btn_for button:nth-child(1) {
				/*	margin-left: 30%;
				 margin-right: 10%;*/
			}
			body {
				background-color: #FFFFFF
			}
			html {
				background-color: #FFFFFF
			}
			.line_heigt_px {
				line-height: 1.2em;
			}
			.textarea_t {
				height: 120px;
				font-size: 16px;
				font-family: "微软雅黑";
				color: #909090;
				border: 1px solid #d9d9d9;
				line-height: 25px;
				padding: 6px 10px;
			}
			.button_blue {
				background-color: #18B4ED;
			
				color: #FFFFFF;
				border-radius: 3px;
				padding: 5px 10px;
			}
			.content_div {
				background: #fff;
				padding-left: 10px;
				padding-top: 10px;
				padding-right: 10px;
				margin-top: 66px;
			}
			.bottom_10 {
				margin-bottom: 10px;
			}
			#filehtml {
				margin-right: 10px;
				margin-left: 5px;
			}
			.btn_bottom0 {
				bottom: 10px;
				width: 100%;
				position: fixed;
				padding-left: 10px;
				padding-right: 10px;
			}
			#tgvalue {
				background-color: #ff9900;
				border: 1px solid #ff9900;
				width: 40%;
			}
			#reject {
				width: 40%;
				margin-right: 30px;
				background-color: #ffffff;
				color: #ff9900;
				border: 1px solid #ff9900;
			}
			.img_add_fujian{
			    width: 70px;
			}
			.CellFrame {
				float: left;
				position: relative;
				padding-left: 10px;
				padding-top: 10px;
				padding-bottom: 10px;
				width: 33%;
				height: 120px
			}
			.picCell {
				width: 100%;
				height: 100%
			}
		</style>
	</head>
	<body>
		
			<div class="base_style_color" id='BarAppearance' style="height: 22px;width: 100%; position:fixed; left: 0px;top:0px;"></div>
			<div class="base_navigation_bar base_style_color base_navigation_item_bar" style="position: fixed;left: 0px;">
				<a class="base_left_item" href="#" onclick="onBackClick()"> <img class="base_back_icon" src="../../image/icon_jiantou.png" alt=""> </a>
				<span id='nav_title'>作业</span>
				<a class="base_right_item base_hide_item"   id="bewrite" ></a>
			</div>
			<div id="main"  style="margin-bottom: 50px;">
			<div class="content_div" >
			
				<p class="line_heigt_px letter_lien base_black_grey base_nav_title_font">
					作业内容
				</p>
				<p id="content"  class="bottom_10  text_indent_2  base_title_font base_dark_grey" style="word-wrap:break-word;word-break:break-all;">
																						
				</p>
					<!--添加图片！！！！-->
				<div id="addPhoto">
				<!--<div class="CellFrame">
						<img class="picCell" src="../../icon/icon_picAdd.png" >
					</div>-->
					
				</div>
			</div>
			
			<div  id ="stdfujin" class=" top_10 padding_left_10 " style="display: none;">
				<em class="line_heigt_px  base_title_font  base_dark_grey left" style="margin-top: 3px;" > 附件： </em>
				<em id="teacher_attachmentTableView"   class="left" style="width: 84%"> <!--	<div class="font16"> <a class="a_style_xiazai" >下周完成巍问问周完成巍问问周完成巍问问          <span style="margin-left: 10px;margin-right: 10px;color: #333333;">(16.0M)</span><img  class="img_style_xiazai" src="../../image/icon_xiazai.png" /></a></div>
				</div>--> </em>
			</div>
			<div class="top_10  padding_left_10 clearfix" >
				<em class="line_heigt_px base_title_font  base_black_grey left"style="padding-top: 3px;"> 评分： </em>
							<input type="text"   id="score" maxlength="5" class="left font16" style="width: 80px;height: 24px;color: red;padding-top: 0px; padding-bottom: 0px;" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')"  />
				<!--<input type="tel"   id="score" maxlength="3" class="left font16" style="width: 66px;height: 24px;color: red;padding-top: 0px; padding-bottom: 0px;" />-->
			</div>
			<div class="top_10 padding_left_10 clearfix" style="padding-left: 10px;">
				<em class="line_heigt_px base_title_font  base_black_grey left"> 评语： </em>
				<div style="width: 80%" class=" left">
					<textarea class="textarea_t bottom_10 " id="comment"  style="color: #363636" placeholder='请在此填写评语'></textarea>
				</div>
			</div>
			<div class="fileDiv " id="imgDiv" >
				<ul id="filehtml" >
			<!--	<div style="margin-left: 50px;" id="fuj" onclick="AddFile()">
			
				<img  class="img_add_fujian" src="../../icon/icon_picAdd.png" alt="">
		        <span class="font12 base_dark_grey">上传批注文件</span>
		         <span class="font12 base_dark_grey">仅支持以下格式:jpg/gif/png/jpeg/bmp/doc/xls/ppt/docx/xlsx/pptx/pdf/txt</span>
		        </div>-->
				</ul>
			</div>
			</div>
			<div class="btn_for btn_bottom0" id="botton_div" >
				<div    style="text-align: center;" >
					<button id="reject"   type="button" class="mui-btn mui-btn-warning top_20"   onclick="Addreject()"  >
						驳回
					</button>
					<button id="tgvalue"  type="button" class="mui-btn mui-btn-warning top_20"  onclick="through()" >
						通过
					</button>
					<div></div>
				</div>
			</div>
			<div id="offlineAlert" class="weui_dialog_confirm" style="display: none;">
				<div class="weui_mask"></div>
				<div class="weui_dialog">
					<div class="weui_dialog_hd">
						<strong class="weui_dialog_title ">是否放弃在此页面操作？</strong>
					</div>
					<div class="weui_dialog_bd"></div>
					<div class="weui_dialog_ft">
						<a onclick="cleanCancel()" href="#" class="weui_btn_dialog default" style="color:#18b4ed"  >取消</a>
						<a onclick="cleanConfirm()" href="#" class="weui_btn_dialog primary"  style="color:#18b4ed">确定</a>
					</div>
				</div>
			</div>
			<div id="Alert" class="weui_dialog_confirm" style="display: none;">
				<div class="weui_mask"></div>
				<div class="weui_dialog">
					<div class="weui_dialog_hd">
						<strong class="weui_dialog_title" id="weui_dialog_title_score">作业评分：80分,确定提交吗</strong>
					</div>
					<div class="weui_dialog_bd"></div>
					<div class="weui_dialog_ft">
						<a onclick="Cancel()" href="#" class="weui_btn_dialog default">取消</a>
						<a onclick="Confirm()" href="#" class="weui_btn_dialog primary"  style="color:#18b4ed">确定</a>
					</div>
				</div>
			</div>
			<div class="noSign" hidden="hidden" id="noData">
				<div style="width: 100%;height: 30px;"></div>
				<img src="../../image/icon_img.png" width="60%">
				<p class="font16 top_15 base_dark_grey" >
					暂无数据
				</p>
			</div>
			<div class="loadFailure" hidden="hidden" id="noNet">
				<img src="../../image/icon_img01.png" width="60%">
				<p class="" >
					数据加载失败
				</p>
				<p>
					请检查您的网络
				</p>
				<button type="button"  onclick="loadData()"class="mui-btn mui-btn-outlined">
					重新加载
				</button>
			</div>
	</body>
	<script type="text/javascript" src="../../script/jquery.min.js"></script>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script src="../../script/common.js"></script>
	<script src="../../script/timeStampTool.js"></script>
	<script src="../../script/processing_images.js"></script>
	<script src="../../script/attachmentManager.js"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript" src="../../script/mui.min.js"></script>
	<script type="text/javascript" src="../../script/databaseOperation.js"></script>
	<script type="text/javascript">
		//附件地址集合
		var urlArr = new Array();
		//文件大小
		var SizeArr = [];
		//上传后的图片路径对象
		var picurls = [];
		//文件名
		var NameArr = [];
		//空格回车正则判断
		var parten = /^\s*$/;
		//上传文件路径
		var fileurl = '';
		var filename = '';
		var filesize = '';
		var str = "";
		var arr = new Array('jpg', 'gif', 'png', 'jpeg', 'bmp', 'doc', 'xls', 'ppt', 'docx', 'xlsx', 'pptx', 'pdf', 'txt');
		var homeworkms = '';
		var strfile = "";
		//上传得文件
		//	    var num=0;//文件的个数
		var pid = "";
		var vid = "";
		var uid = "";
		var jid = "";
		var studyid = '';
		var wid = '';
		var stuname = '';
		var score = '';
		//老师打分
		var comment = '';
		//评语
		var filed = [];
		var pageParam = '';
		DBReady = function() {
			getpageParamdata();
			setupDownloadAttNotifi();
			bewrite();
			loadData();
			listfile();
			jianpanScroll();
			$('#fuj').show();
			api.addEventListener({
				name : 'keyback'
			}, function(ret, err) {
				showAlert();
			})
			sendBuriedNotifi(0, '老师端作业章节批改页', '069');
			
		}
		
		function sendBuriedNotifi(busionessid, pagetype, pagetypeid) {
			var userinfo = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				uname : $api.getStorage('cfnetppusername'),
				cid : api.pageParam.cid,
				pid : api.pageParam.pid,
				vid : api.pageParam.vid
			}
			var data = {
				busionessid : busionessid,
				pagetype : pagetype,
				pagetypeid : pagetypeid,
				sourceurl : api.pageParam.sourceurl,
				sourcetitle : api.pageParam.sourcetitle,
				accesspageurl : window.location.pathname,
				accesspagetitle : document.title,
				userinfo : userinfo
			}
			SendBehaviorTrajectoriesNotifi_Study(data);
		}
		
		
		function bewrite() {
			$('#nav_title').html(stuname);
	
		}

		function getpageParamdata() {
			pageParam = api.pageParam;
			cid = pageParam.cid;
			vid = pageParam.vid;
			pid = pageParam.pid;
			wid = pageParam.wid;
			studyid = pageParam.studyid;
			stuname = pageParam.name;
		}

		// 批阅作业
		function loadData() {
			showProgress();
			var params = {
				jid : $api.getStorage('cfnetppjxid'),
				//				uid:"11924",
				uid : $api.getStorage('cfnetppuid'),
				cid : cid,
				vid : vid,
				pid : pid,
				wid : wid,
				studyid : studyid
			};
			cfnetppPOST(url_getTeacherWorks, params, true, function(data, status) {
//								alert(JSON.stringify(params));
//								alert(JSON.stringify(data));
				api.hideProgress();
				api.refreshHeaderLoadDone();
				if (status == 'success') {
					if (data.code == 200) {
						var datajson = data.json;
						if (datajson != '') {
							$('#noData').hide();
							$('#noNet').hide();
							setdata(datajson);
						} else {
							$('#noData').show();
							$('#noNet').hide();
							$('#main').hide();
						}
					} else if (data.code = 109) {
						$('#noData').show();
						$('#noNet').hide();
						$('#main').hide();
					} else {
						$('#noData').show();
						$('#noNet').hide();
						$('#main').hide();
					}
				} else {
					$('#noData').hide();
					$('#noNet').show();
					$('#main').hide();
				}
			});
		}

		function setdata(data) {
			$('#content').text(removeHtmlTab(escape2Html(data.content)));
			listImg(data.imglist);
			if (data.hasOwnProperty('file')) {
				//	alert(JSON.stringify(pageParam.name));
				var file = data.file;
				var reg = /[a-zA-Z]/g;
				var attArr = new Array();
				var fid = MD5(file.fileurl);
				fid = fid.replace(reg, "");
				fid = fid.substring(0, 5);
				stuData = {
					id : fid,
					url : file.fileurl,
					size : file.filesize,
					name : file.filename
				};
				$("#stdfujin").show();
				var arr = [];
				arr.push(stuData);
				saveAttDatasToDb(arr, '#teacher_attachmentTableView');
			}
		}
	 function listImg(data){
	 if(data == undefined || data == null || data == '' ){
		return;
		}
		  var imageHtmls = '';
		 for(var i=0;i<data.length;i++){
		 var imageHtml= '<div class="CellFrame">'+
						'<img class="picCell" src='+data[i]+' onClick="showimg('+ "'" +data[i]+ "'"+"," + 0 +')">'+
					'</div>';
		 imageHtmls = imageHtmls + imageHtml;
		 }
		$("#addPhoto").html(imageHtmls);
		}


		//UI显示
		function listfile() {
	        var str2="仅支持以下格式:jpg/gif/png/jpeg/bmp/doc/xls/ppt/docx/xlsx/pptx/pdf/txt";
			var num = urlArr.length;
			var imageHtmls = '';
			if (num > 0 && num < 11) {
				for ( i = 0; i < num; i++) {
					var imageHtml = '<li dataid="' + num + '"  class="mui-table-view-cell " >' + '<a class=" base_content_font" href="#" >' + '<span class="base_grey left_text">' + NameArr[i] + '</span>' + ' <span id="company_name " class="base_grey right_text padding_left_10">' + SizeArr[i] + '</span> <img class="  right"    src="../../image/remove.png"  width="20" height="20"  onClick="deleteImg(' + i + ')" >' + '</a>' + '</li>';
					imageHtmls = imageHtmls + imageHtml;
				}
			}
		
			var seleimg = '<div style="margin-left: 50px;" id="fuj" onclick="AddFile()">'+
				'<img  class="img_add_fujian" src="../../icon/icon_picAdd.png" alt="">'+
		       ' <span class="font12 base_dark_grey">上传批注文件</span>'+
		        ' <span class="font12 base_dark_grey Word_wrap">'+str2+'</span>'+
		        '</div>';
			imageHtmls = imageHtmls + seleimg;
			$("#filehtml").html(imageHtmls);
		}

		//添加附件
		function miuilist() {
			var fileBrowser = api.require('fileBrowser');
			fileBrowser.open(function(ret, err) {
				if (ret) {
					//文件地址
					var url = ret.url;
					fileBrowser.close();
					//文件名
					var fileName = splitFileName(url);
					//文件后缀ming
					var ext = fileName.replace(/.+\./, "");
					//小写格式
					var extLower = ext.toLowerCase();
					////根据文件地址判断文件大小是否超过10M
					var fs = api.require('fs');
					fs.getAttribute({
						path : url
					}, function(ret, err) {
						//大小，10M转换为b
						if (ret.attribute.size > 10485760) {
							ShowToast('上传的文件过大');
						} else if (arr.toString().indexOf(extLower) == -1) {
							ShowToast('文件格式不符合要求');
						} else if (urlArr.toString().indexOf(url) > -1) {
							ShowToast('不允许重复提交');
						} else {
							urlArr.push(url);
							var num = urlArr.length;
							SizeArr.push(bytesToSize(ret.attribute.size));
							NameArr.push(fileName);
							listfile();
							if (num > 0) {
								api.showProgress({
									style : 'default',
									animationType : 'fade',
									title : '上传文件中...',
									text : '请稍后...',
									modal : false
								});
								 var pathType = plitFileType(url) + '';
								//图片
								if (pathType == 'jpg' || pathType == 'gif' || pathType == 'png' || pathType == 'jpeg' || pathType == 'bmp') {
									var Upload_File_url = Upload_File_img;
								} else {
									var Upload_File_url = Upload_File_file;
								}
								//上传文件至百度云
								UploadFile_ali(Upload_File_url, url, function(ret) {
									if (ret) {
									
										hideProgress();
										picurls.push(ret.fileurl);
										
									}
								});
							} else {
								str = '';
							}
							$('#fuj').hide();
						}
					});
				}
			});
		}

		//删除附件
		function deleteImg(i) {
			//删除第i个位置开始第一个元素
			picurls.splice(i, 1);
			urlArr.splice(i, 1);
			SizeArr.splice(i, 1);
			NameArr.splice(i, 1);
			listfile();
			$('#fuj').show();
		}

		//添加附件
		function AddFile() {
			if (api.systemType == "ios") {
				ShowToast('苹果手机不支持上传附件，请登录网页进行提交！');
			} else {
				miuilist();
			}
		}

		function showAlert() {
			comment = $('#comment').val();
			score = $('#score').val();
			if (comment.length > 0 || score != '') {
				$('#offlineAlert').show();
			} else {
				backClick();
			}
		}

		//取消
		function cleanCancel() {
			$('#offlineAlert').hide();
		}

		//确定
		function cleanConfirm() {
			$('#offlineAlert').hide();
			api.closeWin({
			});
		}

		// 批阅作业
		function through() {
			comment = $('#comment').val();

			score = $('#score').val();
			if (score == '') {
				ShowToast('评分不能为空');
				return;
			}
			if (parseInt(score) > 100) {
				ShowToast('评分不能超出100分');
				return;
			}

			$('#Alert').show();
	
			$('#weui_dialog_title_score').html("作业评分：" + Number(score) + "分,确定提交吗");
		}

		//取消
		function Cancel() {
			$('#Alert').hide();
		}

		// 批阅作业
		function Confirm() {
			var url = '';
			var size = '';
			var name = '';
			if (picurls.length>0 ) {
			  url = picurls[0];
			  name= NameArr[0];
			size  = SizeArr[0];
			}
			showProgress();
			var params = {
				jid : $api.getStorage('cfnetppjxid'),
		
				uid : $api.getStorage('cfnetppuid'),
				cid : cid,
				vid : vid,
				pid : pid,
				wid : wid,
				studyid : studyid,
				score : score,
				comment : comment,
				status : '2',
				fileurl : url,
				filename : name,
				filesize : size,
				message:api.pageParam.name+'的作业',
			};
			cfnetppPOST(url_teacherwork, params, true, function(data, status) {
				//coding...
				//				alert(JSON.stringify(params));
				$('#Alert').hide();
				hideProgress();
				SendBusinessOperationsLogNotifi('老师端批阅作业页', '067', params, params, '', data, '老师端批阅作业接口', '067-01')
				if (data) {
					if (data.code == "200") {
						api.toast({
							msg : '批阅上传成功'
						});
						
						api.sendEvent({
							name : 'Teach_freecourse_homeworks',
							extra : {
								sid : studyid,
								type : 2,
								name : stuname,
								score : score,
							}
						});
				        
//						sendBuriedNotifi(1, '查看作业信息', '069');
						if(pid == 5017){
						  var xjid=$api.getStorage('cfnetppjxid');//教学
						  var sjid=$api.getStorage('cfnetppjid');//实习
						  if(xjid == '' || xjid == null||sjid == '' || sjid == null){
							    ApplyAccount();
							   }
						    }
						   backClick();
						
					} else {
						cleanCancel();
						var tishi = "数据请求出错！！！";
						if (data.code == "100" || data.code == "109") {
							tishi = "作业提交失败";
						}
						if (data.code == "101") {
							tishi = "参数错误";
						}
						if (data.code == "106") {
							tishi = "章节未找见";
						}
						if (data.code == "107") {
							tishi = "作业未找见";
						}
						if (data.code == "118") {
							tishi = "作业已经过期";
						}
						if (data.code == "119") {
							tishi = "作业已经提交过";
						}
						ShowToast(tishi);
					}
				} else {
					ShowToast("提交失败");
				}
			});
		}

		//描述
		function openBewrite() {
			api.openWin({useWKWebView:true,
				name : 'Student_Free_bewrite',
				url : '../Study/Student_Free_bewrite.html',
				pageParam : {
					title : pageParam.title,
					bewrite : api.pageParam.bewrite,
					is_dis_bewrite : api.pageParam.is_dis_bewrite
				}
			});
		}

		function onBackClick() {
			showAlert();
		}

		function backClick() {
		sendBuriedNotifi(1, '老师端作业章节批改页', '069');
			api.closeWin({
			});
		}

		//驳回
		function Addreject() {
			api.openFrame({
				name : 'Teach_homework_Addreject',
				url : 'Teach_homework_Addreject.html',
				pageParam : {
					studyid : studyid,
					stuname : stuname,
					cid : cid,
					vid : vid,
					pid : pid,
					wid : wid,
				},
			});
		}

		//键盘弹出监听
		function jianpanScroll() {
			var winHeight = $(window).height();
			//获取当前页面高度
			$(window).resize(function() {
				var thisHeight = $(this).height();
				if (winHeight - thisHeight > 50) {
					//当软键盘弹出，在这里面操作
					$("#botton_div").css('display', 'none');
				} else {
					$("#botton_div").css('display', 'block');
					//当软键盘收起，在此处操作
				}
			});
		}


	//长风模式体验申请
	function ApplyAccount() {
	var params = {
				jid : 419,
				uid : $api.getStorage('cfnetppuid'),
				pid : pid,
				wid : wid,
				}
		cfnetppPOST(url_TecGetWorkNum, params, true, function(data, status) {
//		alert(JSON.stringify(data));
			if (data) {
				if (data.code == "200") {
				   var datas= data.data;
				    if(datas.num > 2&& datas.iscfnt ==0){
					   api.confirm({
							title: '提示',
							msg: '长风模式体验申请',
							buttons: ['确定', '取消']
						}, function(ret, err) {
						    var index = ret.buttonIndex;
						    if(index==1){//确定
					         api.openWin({useWKWebView:true,
				              name :'changfengmoshiApply',
				              url :'../changfengmoshiApply.html'});
				               setTimeout(function () {
							          backClick();
				                  }, 1000);
					             
						    }else{//取消
						     backClick();
						    }
	                       
						});
					}else{
					 backClick();
					}
				}
			}
		})
	}

	</script>
</html>